package com.example.demo.quartz;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class SchedulerTask {

    @Scheduled(cron = "*/6 * * * * ?")
    private void cronProcess(){
        System.out.println("now time is " + getTime());
    }

    @Scheduled(fixedRate = 6000)
    private void fixedRateProcess(){
        System.out.println("now time is " + getTime());
    }

    private String getTime(){
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTime.format(formatter);
    }
}
